#include <winsock2.h>
#include <mswsock.h>
#include <WS2tcpip.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
main(
	int argc,
	char **argv)
{
	WSADATA wsaData;
	int ret = 0;
	SOCKET s = INVALID_SOCKET;
	struct sockaddr_in addr4;
	char buf[1024];
	int len;

	ret = WSAStartup(MAKEWORD(2, 2), &wsaData);
	if (ret != 0) {
		return -1;
	}

	s = socket(PF_INET, SOCK_STREAM, 132);
	if (s == INVALID_SOCKET) {
		fprintf(stderr, "socket: %u\n", WSAGetLastError());
		return -1;
	}
	addr4.sin_family = AF_INET;
	inet_pton(AF_INET, argv[1], &addr4.sin_addr);
	addr4.sin_port = htons(atoi(argv[2]));
	ret = connect(s, (struct sockaddr *)&addr4, sizeof(addr4));
	if (ret == SOCKET_ERROR) {
		fprintf(stderr, "connect: %u\n", WSAGetLastError());
		return -1;
	}
	Sleep(1000);
	len = recv(s, buf, sizeof(buf), 0);
	printf("len=%d\n", len);
	closesocket(s);

	return 0;
}